IF OBJECT_ID('dbo.UpdateAgrDemographicValidataionLog') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.UpdateAgrDemographicValidataionLog
    IF OBJECT_ID('dbo.UpdateAgrDemographicValidataionLog') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.UpdateAgrDemographicValidataionLog >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.UpdateAgrDemographicValidataionLog >>>'
END
GO

-- =======================================================================
-- Procedure Name: dbo.UpdateAgrDemographicValidataionLog
--
-- Author:      Chris Bernard, Parallax Consulting LLC
--
-- Create date: 8/09/2007
--
-- Description: Source of Report, "UpdateAgrDemographicValidataionLog"
--                  In Insight DB Reporting Services
--
-- Parameters:  
-- 
--              
-- Returns:     INT, 0=Success, -1=Error
--
-- SampleCall:
-- EXECUTE dbo.UpdateAgrDemographicValidataionLog()
--
--------------------------------------------------------------------------
-- Date        Initials  Modification
--------------------------------------------------------------------------
-- 8/09/07     CB        Created
-- 1/3/2008	   CB        Added additional checks FAILURE_COMPOSITE_CHECK_INFOED,
--                       EMPTY_PHS_LOCATION,MISMATCH_FUND_CODE,MISMATCH_BUDGET_START,
--					     MISMATCH_BUDGET_END,MISMATCH_INDIRECT_COST_BASE,MISMATCH_INDIRECT_COST_RATE,
--				         MISMATCH_CDFA,MISMATCH_ACCOUNT_CYCLE
-- 3/31/2008    CB		 Added logic for MISMATCH_INDIRECT_COST given by Research Finance to remove
--                       discrepencies that were duue to code differences at BWH (They were not true
--                       just because the values did not match exactly between PS and InfoED    
-- 6/24/2008	CB		 Added code to handle duplicate mappings in the Stg_IE_DemogFeed_InfoEdFunds table
-- 8/18/2008    CB		 Fixed Duplicate and issues with invalid characters for Spon Award, Added logic to remove
--						 to remove non research funds, Added logic to remove advance funds in Budget checks,
--						 Fixed Budget Start and End checks to get the most current period which is what should match to PS.
-- 9/8/2008		CB		 Fixed bug with Budget Start Date Check
-- 9/11/2008	CB		 Added code to excluded UNRESTRICT_AGENCY fund code 
-- 10/5/2008    CB		 Changed exclude logic to use numeric fund codes, modified PI check to use usersname, modified fund code check,
--						 Added detail fields for detail report
-- 10/16/2008	CB		 Added logic to handle PI Check if username is in the AdmPerson_RecomAbstract_Map table mulitple times
-- 2/16/2008	CB	     Modify logic to check budget start and budget end from Agreement Budget table. Modify PI compare to use login id 
-- =======================================================================
CREATE PROCEDURE [dbo].[UpdateAgrDemographicValidataionLog]
AS
BEGIN
    -- Initial Settings
	SET NOCOUNT ON

    -- Declare Local Variables

    DECLARE   @Error INT,
              @RowCount INT,
              @LogDate DATETIME,
			  @ErrorCode VARCHAR(200),
			  @CompareBaseDate DATETIME

    SET @LogDate = CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),101))
    
    SELECT @CompareBaseDate =MAX(LogDate) FROM Stg_AgrDemographicValidataionLog WHERE CompareBaseDateFlag =1  
    IF @CompareBaseDate IS NULL SET @CompareBaseDate ='10/31/2008' --First date being reviewed from recom team
    

    DELETE FROM Stg_AgrDemographicValidataionLog WHERE LogDate = @LogDate
    DELETE FROM Stg_AgrDemographicValidataionErrorLog WHERE LogDate = @LogDate
    DELETE FROM Stg_AgrDemographicValidataionErrorDetail WHERE LogDate = @LogDate OR (LogDate <= DATEADD(d,-60,@LogDate) AND LogDate <> @CompareBaseDate)


	--Create mapping table due to fundcode change in PS. PS used to send fundcode desciption but it is now sending numeric code
	CREATE TABLE #FundCode
	    (PSFundcode VARCHAR(10),
	     PSFundCodeDescription VARCHAR(100),
	     InfoeEdFundCodeDescription VARCHAR(100))
	     
	INSERT INTO #FundCode VALUES('066','Brd Sundry-Research','RESEARCH_SUNDRY')
	INSERT INTO #FundCode VALUES('068','Brd Sundry-Rsrch Private Found','RESEARCH_PRV_FOUNDTN')
	INSERT INTO #FundCode VALUES('070','NIH','RESEARCH_NIH')
	INSERT INTO #FundCode VALUES('078','Exchange-Billing','RESEARCH_BILLABLE')
	INSERT INTO #FundCode VALUES('072','Non-Federal Research','RESEARCH_NONFEDERAL')
	INSERT INTO #FundCode VALUES('071','Other Federal - Project','RESEARCH_OTHER_FED')
	
	--Create Temp Table to remove duplicate foldernumber and ps fund mappings
	SELECT DISTINCT sfoldernumber,prop_no,sPSFundNumber,dtActivated INTO #Stg_IE_DemogFeed_InfoEdFunds
	FROM Stg_IE_DemogFeed_InfoEdFunds
	
		
	--Create Temp table to only incude PS Fund Codes that should  be include in reconcitliation
	-- The following codes have been identified: (066) Brd Sundry-Research,(068) Brd Sundry-Rsrch Private Found,(078) Exchange-Billing,
	--(070) NIH, (072) Non-Federal Research,(071) Other Federal - Project
	
	SELECT * INTO #Stg_IE_DemogFeed 
	  FROM dbo.Stg_IE_DemogFeed
	 WHERE Fund_Code  IN ('066','068','070','071','072','078') 
	
    --Populate Log Summary Information 
    INSERT INTO dbo.Stg_AgrDemographicValidataionLog
	SELECT @LogDate AS LogDate,
           SUM(CASE WHEN Business_Unit = '1200' AND Effective_Status ='A' AND FMap.sPSFundNumber IS NOT NULL  THEN 1 ELSE 0 END) AS MGHActiveCnt,
           SUM(CASE WHEN Business_Unit = '1200' AND Effective_Status ='I' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS MGHInactiveCnt,
           SUM(CASE WHEN Business_Unit = '2200' AND Effective_Status ='A' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS BWHActiveCnt,
           SUM(CASE WHEN Business_Unit = '2200' AND Effective_Status ='I' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS BWHInactiveCnt,
           SUM(CASE WHEN Business_Unit NOT IN ('1200','2200') AND Effective_Status ='A' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS OtherActiveCnt,
           SUM(CASE WHEN Business_Unit NOT IN ('1200','2200') AND Effective_Status ='I' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS OtherInactiveCnt,
           SUM(CASE WHEN Effective_Status ='A' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS ActivPSGrantNumberMatchCnt,
           SUM(CASE WHEN Effective_Status ='I' AND FMap.sPSFundNumber IS NOT NULL THEN 1 ELSE 0 END) AS InactivePSGrantNumberMatchCnt,
           COUNT(*) AS TotalFileRecCnt,
           0 AS CompareBaseDateFlag
	  FROM #Stg_IE_DemogFeed PS
	  	   LEFT OUTER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber

    --******************************
	--Check Composite Check Failures 
    --******************************
	--Populate Composite Check Failures 
    SET @ErrorCode ='FAILURE_COMPOSITE_CHECK'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
		    PS.Project_Grant,PS.Folder_Number,
		    PS.Project_Grant AS PSValue,
            FMAP.sPSFundNumber AS InfoEdValue,
            Effective_Status
	  FROM #Stg_IE_DemogFeed PS
		   LEFT OUTER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
	 WHERE FMAP.sPSFundNumber IS NULL 
           AND (ISNULL(Folder_Number,'') = '' OR  SUBSTRING(PS.Folder_Number,5,1)<>'I') --I in folder # indicates sundry fund and should not be in InfoED
	END

    SET @ErrorCode ='FAILURE_COMPOSITE_CHECK_INFOED'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,BusinessUnitNumber,
            SUBSTRING(sPSFundNumber,1,6) AS sPSFundNumber,sfoldernumber,
            NULL AS PSValue,
            CASE WHEN dtActivated IS NOT NULL THEN sPSFundNumber + ' (' + CONVERT(VARCHAR(10),dtActivated,101) + ')' ELSE  sPSFundNumber END AS InfoEdValue,
			'A' AS  Effective_Status
       FROM #Stg_IE_DemogFeed_InfoEdFunds i
   	        INNER JOIN Stg_IE_AgrAgreement InfoEd ON i.Prop_NO = InfoEd.Prop_NO
		    LEFT OUTER JOIN Stg_IE_SvcEntity_FwkDomainOrganization_Map BU ON i.Prop_NO = BU.Prop_NO
		    LEFT OUTER JOIN FwkDomainOrganization INST ON BU.FwkDomainOrganizationId = INST.Id
			LEFT OUTER JOIN #Stg_IE_DemogFeed d on d.project_grant = i.spsfundnumber
		    LEFT OUTER JOIN agrfund_agragreement_map fam on fam.fundnumber = i.spsfundnumber
	  WHERE d.project_grant is null and fam.fundnumber is NULL AND BusinessUnitNumber IS NOT NULL 
	END 
	
	--*******************************
	--Populate PS Validation Errors
    --*******************************
	--Populate BUDGET_END_DT_GR_10_YEARS Errors
	SET @ErrorCode ='BUDGET_END_DT_GR_10_YEARS'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
            project_Grant,
            Folder_Number,
            CONVERT(VARCHAR(10),dtBudgetEnd,101) AS PSValue,
            NULL AS InfoEdValue,
            Effective_Status
	   FROM #Stg_IE_DemogFeed PS
     WHERE ISNULL(dtBudgetEnd,'') > DATEADD(yy,10,GETDATE())
           AND dtBudgetEnd <> '12/31/2099'   
	END

	--Populate EMPTY_PHS_LOCATION Errors
    INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
    SELECT  @LogDate AS LogDate,
            'EMPTY_PHS_LOCATION' AS ErrorCode,
            Business_Unit,
            project_Grant,
            Folder_Number,
            NULL AS PSValue,
            NULL AS InfoEdValue,
            Effective_Status
     FROM #Stg_IE_DemogFeed
     WHERE Len(ISNULL(location_code,'')) = 0  

    --******************************************
	--Check Agreement Demographic Discrepencies
    --******************************************
	--Check business unit
    SET @ErrorCode ='MISMATCH_BUSINESS_UNIT'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
		    PS.Project_Grant,PS.Folder_Number,
		    PS.Business_Unit AS PSValue,
            BusinessUnitNumber AS InfoEdValue,
            Effective_Status
	  FROM #Stg_IE_DemogFeed PS
		   INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
	       INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
		   LEFT OUTER JOIN Stg_IE_SvcEntity_FwkDomainOrganization_Map BU ON FMAP.Prop_NO = BU.Prop_NO
		   LEFT OUTER JOIN FwkDomainOrganization INST ON BU.FwkDomainOrganizationId = INST.Id
	 WHERE ISNULL(PS.Business_Unit,'') <> ISNULL(INST.BusinessUnitNumber,'')
	END

	--Check Chief Code
	SET @ErrorCode ='MISMATCH_CHIEF_CODE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
		    PS.Project_Grant,PS.Folder_Number,
		    PS.Dept_Code AS PSValue,
            ChiefCode AS InfoEdValue,
            Effective_Status
	  FROM #Stg_IE_DemogFeed PS
		   INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
		   INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
		   LEFT OUTER JOIN Stg_IE_SvcEntity_FwkDomainOrganization_Map BU ON FMAP.Prop_NO = BU.Prop_NO
	 WHERE ISNULL(PS.Dept_Code,'') <> ISNULL(BU.ChiefCode,'')
	END

	--Check Project Start
	SET @ErrorCode ='MISMATCH_PROJ_ST_DT'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
		    PS.Project_Grant,PS.Folder_Number,
		    CONVERT(VARCHAR(10),CONVERT(DATETIME,PS.Proj_Start_Date),101) AS PSValue,
		    CONVERT(VARCHAR(10),InfoEd.ProjectStartDate,101) AS InfoEdValue,
		    Effective_Status
	  FROM #Stg_IE_DemogFeed PS
		   INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
		   INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
	 WHERE ISNULL(CONVERT(DATETIME,PS.Proj_Start_Date),'') <> ISNULL(InfoEd.ProjectStartDate,'')
	END

	--Check Project End
	SET @ErrorCode ='MISMATCH_PROJ_END_DT'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	  	    PS.Project_Grant,PS.Folder_Number,
		    CONVERT(VARCHAR(10),CONVERT(DATETIME,PS.Proj_End_Date),101) AS PSValue,
		    CONVERT(VARCHAR(10),InfoEd.ProjectEndDate,101) AS InfoEdValue,
            Effective_Status
	   FROM #Stg_IE_DemogFeed PS
	 		INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
	  WHERE ISNULL(CONVERT(DATETIME,PS.Proj_End_Date),'') <> ISNULL(InfoEd.ProjectEndDate,'')
	END

	--Check folder Number
	SET @ErrorCode ='MISMATCH_FOLDER_NUMBER'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
		    PS.Project_Grant,PS.Folder_Number,
		    PS.Folder_Number AS PSValue,
            InfoEd.FolderNumber AS InfoEdValue,
		    Effective_Status
	   FROM #Stg_IE_DemogFeed PS
		    INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
	 	    INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
	  WHERE ISNULL(PS.Folder_Number,'') <> ISNULL(InfoEd.FolderNumber,'')
	END

	--Check Agreement Type
	SET @ErrorCode ='MISMATCH_AGREEMENT_TYPE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
			AAT.Name AS PSValue,
            InfoEd.AgreementType AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
			INNER JOIN AgrAgreementType AS AAT ON PS.AgrAgreementTypeId = AAT.ID
	  WHERE ISNULL(AAT.Name,'') <> ISNULL(InfoEd.AgreementType,'')
	END

	--Check Activity Type
	SET @ErrorCode ='MISMATCH_ACTIVITY_TYPE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	        PS.Project_Grant,PS.Folder_Number,
			PS.Activity_Type_Code AS PSValue,
			InfoEd.ActPSCode AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
	  WHERE ISNULL(Activity_Type_Code,'') <> ISNULL(InfoEd.ActPSCode,'')
	END

	--Check Effective Status
	SET @ErrorCode ='MISMATCH_EFF_STATUSES'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
			PS.Effective_Status AS PSValue,
			CASE WHEN InfoEd.Status IN('Closed','Hold') THEN 'I' ELSE 'A' END  + ' (' + InfoEd.Status + ')' AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
	  WHERE ISNULL(PS.Effective_Status,'') <> ISNULL(CASE WHEN InfoEd.Status IN('Closed','Hold') THEN 'I' ELSE 'A' END,'')
	END

    --Check PI
	SET @ErrorCode ='MISMATCH_PI_NAME'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
			PILoginId + ISNULL(' (' +  RTRIM(PS.mgr_first_name) + ' ' + RTRIM(PS.mgr_Last_name)  + ' )','') AS PSValue,
			PIUserName + ISNULL(' (' + RTRIM(P.FirstName) + ' ' + RTRIM(P.LastName) + ')','') AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
			LEFT OUTER JOIN 
			(SELECT MAX(AdmPersonId) AS AdmPersonId, RecomUsername FROM  AdmPerson_RecomAbstract_Map
				GROUP BY RecomUsername) RM ON InfoEd.PIUserName = RM.RecomUsername
			LEFT OUTER JOIN dbo.AdmPerson P ON RM.AdmPersonId = P.Id
	  WHERE ISNULL(PS.PILoginId,'') <> ISNULL(InfoEd.PIUserName,'') 
	END

	--Check Sponsor Name
	SET @ErrorCode ='MISMATCH_SPONSOR_NAME'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
		    PS.Sponsor_Name_Upcased AS PSValue,
		    LEFT(SPON.NAME,40) AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
			LEFT OUTER JOIN AdmSponsor SPON ON InfoEd.AdmSponsorID = SPON.ID
	  WHERE (ISNULL(PS.Sponsor_Name_Upcased,'')='' AND SPON.NAME <>'SUNDRY') OR
            (ISNULL(PS.Sponsor_Name_Upcased,'') <> '' AND PS.Sponsor_Name_Upcased <> LEFT(ISNULL(SPON.NAME,''),40))
	END 

	--Check Sponsor Code (Type)
	SET @ErrorCode ='MISMATCH_SPONSOR_CODE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
		    PS.sponsor_code AS PSValue,
		    PSCode AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
		    LEFT OUTER JOIN AdmSponsor SPON ON InfoEd.AdmSponsorID = SPON.ID
            LEFT OUTER JOIN AdmSponsorType ST ON SPON.AdmSponsorTypeId = ST.Id
	  WHERE ISNULL(ST.PSCode,'') <> ISNULL(PS.sponsor_code,'')
	END 

	--Check Sponsor Award #
	SET @ErrorCode ='MISMATCH_SPONSOR_AWARD_NUMBER'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	        PS.Project_Grant,PS.Folder_Number,
		    dbo.fnGetSponsorAwardNumber(PS.sponsor_agree_id) AS PSValue,
		    dbo.fnGetSponsorAwardNumber(ISNULL(P.spon_awd,P.spon_id)) AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
            INNER JOIN InfoEdProposal P ON FMap.Prop_NO  = P.Prop_NO AND  inst_code = 'PARTNERS'
	  WHERE ISNULL(dbo.fnGetSponsorAwardNumber(ISNULL(P.spon_awd,P.spon_id)),'') <> ISNULL(dbo.fnGetSponsorAwardNumber(PS.sponsor_agree_id),'')
	END 

	--Check Doc ID
    SET @ErrorCode ='MISMATCH_DOCUMENT_ID'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
			PS.doc_letter AS PSValue,
		    PUDF.DocumentNumber  AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
            LEFT OUTER JOIN (SELECT PropNumber,DocumentNumber FROM InfoEdUDFProposal) PUDF ON FMap.Prop_NO  = PUDF.PropNumber
	  WHERE ISNULL(PUDF.DocumentNumber,'') <> ISNULL(PS.doc_letter,'')
	END 

	--Check Location
	SET @ErrorCode ='MISMATCH_LOCATION'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
			PS.Project_Grant,PS.Folder_Number,
			Location_Code AS PSValue,
			F.PSCode AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN Stg_IE_AgrAgreement InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO
			LEFT OUTER JOIN Stg_IE_SvcEntityFacility_Ctl F ON InfoEd.Prop_no=F.prop_no
	  WHERE ISNULL(PS.Location_Code,'') <> ISNULL(F.PSCode,'')
	END

	--Check Fund Code
	SET @ErrorCode ='MISMATCH_FUND_CODE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	 		PS.Project_Grant,PS.Folder_Number,
			fund_code AS PSValue,
			FC.PSFundcode AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN InfoEdUDFProposal InfoEd ON FMap.Prop_NO = InfoEd.PropNumber AND InstCode='PARTNERS'
			LEFT OUTER JOIN #FundCode FC ON InfoEd.FundCode = FC.InfoeEdFundCodeDescription
      WHERE ISNULL(fund_code,'') <> ISNULL(FC.PSFundcode,'')
	END 

	--Check Account Cycle
	SET @ErrorCode ='MISMATCH_ACCOUNT_CYCLE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	 		PS.Project_Grant,PS.Folder_Number,
			acct_cycle_code AS PSValue,
			AccountCycle AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN InfoEdUDFProposal InfoEd ON FMap.Prop_NO = InfoEd.PropNumber AND InstCode='PARTNERS'
      WHERE ISNULL(acct_cycle_code,'') <> ISNULL(SUBSTRING(AccountCycle,1,1),'')
	END 

	--Check CDFA
	SET @ErrorCode ='MISMATCH_CDFA'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	 		PS.Project_Grant,PS.Folder_Number,
			cfda_number AS PSValue,
			fed_catg AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN InfoEdProposal InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO AND Inst_Code='PARTNERS'
    WHERE ISNULL(ps.cfda_number,'') <> ISNULL(fed_catg,'')
	END 

	--Check IC Base
	SET @ErrorCode ='MISMATCH_INDIRECT_COST_BASE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	 		PS.Project_Grant,PS.Folder_Number,
			fibt.Code AS PSValue,
			C.code AS InfoEdValue,
			Effective_Status
	   FROM #Stg_IE_DemogFeed PS
            LEFT OUTER JOIN FinICBaseType AS fibt ON PS.FinICBaseTypeId = fibt.ID
			INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber
			INNER JOIN InfoEdProposal InfoEd ON FMap.Prop_NO = InfoEd.Prop_NO AND Inst_Code='PARTNERS'
            LEFT OUTER JOIN InfoEdCodetab C ON InfoEd.icbm = c.code AND Arr_name ='MTDC_CODE'
	  WHERE ISNULL(fibt.Code,'') <> ISNULL(CASE WHEN PATINDEX ( '%MTDC%' , C.code )>0 THEN 'MTDC' ELSE C.code END,'')
	  
	  --Logic provided by Demog cleanup as not true discrepancies	  	  
	  DELETE FROM Stg_AgrDemographicValidataionErrorDetail
	        WHERE LogDate =@LogDate AND 
	              ErrorCode = @ErrorCode AND
	              ((PSValue ='SW' AND InfoEdValue = 'BWHSW' AND BusinessUnit ='2200') OR 
	               (PSValue='TADC' AND InfoEdValue = 'BTADC' AND BusinessUnit ='2200') OR 
                   (PSValue ='TDC' AND InfoEdValue = 'BTDC' AND BusinessUnit ='2200'))
                  
	END 

	--******************************************
	--Check Agreement Budget Discrepencies
    --******************************************
    --Remove Advance Funds from Fund list. Advance funds should be ignored for Budget reconcilitaion purpose.
    DELETE FROM #Stg_IE_DemogFeed_InfoEdFunds
          WHERE prop_no IN (SELECT PropNumber  FROM InfoEdUDFAward WHERE AdvanceFundYN = 1 AND InstCode ='PARTNERS')

    
	--Check Budget Start
	SET @ErrorCode ='MISMATCH_BUDGET_ST_DT'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	        PS.Project_Grant,PS.Folder_Number,
			CONVERT(VARCHAR(10),Budget_Start_Date,101) AS PSValue,
			CONVERT(VARCHAR(10),BudgetStartDate,101) AS InfoEdValue,
			Effective_Status
	   FROM
		(SELECT folder_number,project_grant,Business_Unit,Effective_Status,
		        Budget_Start_Date,Budget_End_Date
		   FROM #Stg_IE_DemogFeed PS
			    INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber)PS
	  INNER JOIN 
		(SELECT  FundNumber,FolderNumber, MIN(BudgetStartDate) AS BudgetStartDate 
		    FROM AgrAgreement_Budget b
		         INNER JOIN AgrAgreement_Info  AI ON b.agreementid = AI.AgreementId
			WHERE IsAdjustment = 0 AND budgetviewtype ='Awarded'
			     GROUP BY FundNumber,FolderNumber) InfoEd ON PS.folder_number = infoed.foldernumber AND
							 				   PS.project_grant = Infoed.FundNumber
		WHERE ISNULL(CONVERT(DATETIME,PS.Budget_Start_Date),'') <> ISNULL(BudgetStartDate,'')    
	END

	--Check Budget End
	SET @ErrorCode ='MISMATCH_BUDGET_END_DT'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
	 SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	        PS.Project_Grant,PS.Folder_Number,
			CONVERT(VARCHAR(10),Budget_End_Date,101) AS PSValue,
			CONVERT(VARCHAR(10),BudgetEndDate,101) AS InfoEdValue,
			Effective_Status
	   FROM
		(SELECT folder_number,project_grant,Business_Unit,Effective_Status,
		        Budget_Start_Date,Budget_End_Date
		   FROM #Stg_IE_DemogFeed PS
			    INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber)PS
	  INNER JOIN 
		(SELECT  FundNumber,FolderNumber, MAX(BudgetEndDate) AS BudgetEndDate 
		    FROM AgrAgreement_Budget b
		         INNER JOIN AgrAgreement_Info  AI ON b.agreementid = AI.AgreementId
			WHERE IsAdjustment = 0  AND budgetviewtype ='Awarded'
			     GROUP BY FundNumber,FolderNumber) InfoEd ON PS.folder_number = infoed.foldernumber AND
							 				                 PS.project_grant = Infoed.FundNumber
		WHERE ISNULL(CONVERT(DATETIME,PS.Budget_End_Date),'')<> ISNULL(BudgetEndDate,'')  
		
	END

	--Check Indirect Cost Rate
	SET @ErrorCode ='MISMATCH_INDIRECT_COST_RATE'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
     SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,PS.Business_Unit,
	 		PS.Project_Grant,PS.Folder_Number,
			ic_rate AS PSValue,
			ICRate1 AS InfoEdValue,
			Effective_Status
	   FROM
		(SELECT folder_number,project_grant,Business_Unit,Effective_Status,
				Budget_Start_Date,Budget_End_Date,ic_rate
		   FROM #Stg_IE_DemogFeed PS
			    INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON PS.Project_Grant = FMAP.sPSFundNumber)PS
	  INNER JOIN 
		(SELECT  foldernumber,sPSFundNumber,ICRate1
		    FROM Stg_IE_AgrBudget_Ctl 
			WHERE AgrBudgetViewTypeId =3 AND IsAdjustment = 0 
			      AND YEAR = CurrentGrantYear) InfoEd ON PS.folder_number = infoed.foldernumber AND
							 							                                             PS.project_grant = Infoed.sPSFundNumber
		WHERE ISNULL(CONVERT(DECIMAL(10,4),ic_rate),0)<> ISNULL(ICRate1,0)
	END

	--Check Fund Budget Total Cost (Only Awarded budgets from InfoEd are included)
	SET @ErrorCode ='MISMATCH_BUDGET_TOTAL_COST'
    IF (SELECT Count(*) FROM Stg_AdmDemographicValidationError WHERE ErrorCode = @ErrorCode AND Active=1) >0
    BEGIN
     INSERT INTO dbo.Stg_AgrDemographicValidataionErrorDetail (LogDate,ErrorCode,BusinessUnit,PSFundNumber,FolderNumber,PSValue,InfoEdValue,Status) 
     SELECT @LogDate AS LogDate,@ErrorCode AS ErrorCode,Business_Unit,
 	 		Project_Grant,Folder_Number,
			PARSENAME(CONVERT(VARCHAR(100),ISNULL(PS_DC,0) + ISNULL(PS_IC,0),1),2) + ' (DC=' + PARSENAME(CONVERT(VARCHAR(20),PS_DC,1),2) + ' IC=' + PARSENAME(CONVERT(VARCHAR(20),PS_IC,1),2) + ')'AS PSValue,
			PARSENAME(CONVERT(VARCHAR(100),ISNULL(DC,0) + ISNULL(IC,0),1),2) + ' (DC=' + PARSENAME(CONVERT(VARCHAR(20),DC,1),2) + ' IC=' + PARSENAME(CONVERT(VARCHAR(20),IC,1),2)+ ')' AS InfoEdValue,
			Effective_Status
	  FROM
		 (SELECT Fund,
				 SUM(CASE WHEN FA.ID <> 1571 THEN BudgetAmount ELSE 0 END) AS PS_DC,
				 SUM(CASE WHEN FA.ID = 1571 THEN BudgetAmount ELSE 0 END) AS PS_IC
		   FROM  Stg_IE_PSBudget B
 				 INNER JOIN #Stg_IE_DemogFeed_InfoEdFunds FMap ON B.fund = FMAP.sPSFundNumber
				 INNER JOIN finaccount FA on B.Account = FA.Number
		   WHERE FincategoryID NOT IN (10,14) --Letter of credit and revenue
		  GROUP BY Fund) PS
		 INNER JOIN 
		 (SELECT FundNumber,
				SUM(BudgetDirectCost) AS DC,
				SUM(BudgetINDirectCost) AS IC,
				SUM(BudgetTotalAmount) AS TC
		   FROM dbo.AgrAgreement_Budget aab
				INNER JOIN [AgrAgreement_Info]  ai ON  aaB.[AgreementId] = ai.[AgreementId] 
		  WHERE BudgetViewType IN('Awarded') 
		  GROUP BY FundNumber)INSIGHT ON PS.Fund = Insight.FundNumber
		 INNER JOIN #Stg_IE_DemogFeed D ON PS.Fund = D.project_grant
		 WHERE ABS((ISNULL(PS_DC,0) + ISNULL(PS_IC,0)) -
				  (ISNULL(DC,0) + ISNULL(IC,0))) >10
	END
	
	--****************************************************************
	-- Update Fields from PS values to be shown on error detail report
	--****************************************************************
	UPDATE dbo.Stg_AgrDemographicValidataionErrorDetail 
	SET  PSPrincipalInvestigator = PS.mgr_name,
		 PSProposalTitle = PS.description,
		 PSChiefCode = PS.dept_code,
		 PSSponsorName  =  PS.sponsor_name,
         PSProjectStart = PS.proj_start_date,
         PSProjectEnd = PS.proj_end_date,
         PSBudgetStart = PS.budget_start_date,
         PSBudgetEnd = PS.budget_end_date
	FROM Stg_AgrDemographicValidataionErrorDetail ED 
	     INNER JOIN #Stg_IE_DemogFeed PS ON ED.PSFundNumber = PS.project_grant  

	--******************************************
	-- Populate Error Log Summary Information
	--******************************************
    INSERT INTO dbo.Stg_AgrDemographicValidataionErrorLog
    SELECT LogDate,S.ErrorCode,
           COUNT(*) AS Cnt,
           SUM(CASE WHEN  Status ='A' THEN 1 ELSE 0 END) AS ActiveCnt,
           SUM(CASE WHEN BusinessUnit = '1200' AND  Status ='A' THEN 1 ELSE 0 END) AS MGHActiveCnt,         
           SUM(CASE WHEN BusinessUnit = '2200' AND  Status ='A' THEN 1 ELSE 0 END) AS BWHActiveCnt
      FROM dbo.Stg_AgrDemographicValidataionErrorDetail S
     WHERE BusinessUnit IN('1200','2200') AND LogDate =@LogDate
     GROUP BY LogDate,S.ErrorCode
     ORDER BY LogDate,S.ErrorCode

     SELECT @Error=@@ERROR,@RowCount=@@ROWCOUNT
     IF @Error!=0
          RETURN -1

     -- Return Success
     RETURN 0

END
GO
IF OBJECT_ID('dbo.UpdateAgrDemographicValidataionLog') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.UpdateAgrDemographicValidataionLog >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.UpdateAgrDemographicValidataionLog >>>'
GO
GRANT EXECUTE ON dbo.UpdateAgrDemographicValidataionLog TO InsightReport,Insight
GO

